package sourceagile.webservices;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.codehaus.jettison.json.JSONObject;

import sourceagile.server.classRepositories.subversionFileRepository.GetFileContent;
import sourceagile.server.doclet.ConvertClassContentToDocumentation;

@Path("/classDocumentation")
public class GetClassDocumentation {

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public static JSONObject getDoc() {

		String repositoryURL = "https:--tictactoe4j.googlecode.com-svn-trunk";

		String username = "Alline.Oliveira";

		String password = "bD8Km8se2rV9";

		String filePath = "src/tictactoe/client/userInterface";

		String fileName = "PlayerMove.java";

		return getDoc(repositoryURL, username, password, filePath, fileName);

	}

	@GET
	@Path("{repositoryURL}/{username}/{password}/{filePath}/{fileName}")
	@Produces(MediaType.APPLICATION_JSON)
	public static JSONObject getDoc(
			@PathParam("repositoryURL") String repositoryURL,
			@PathParam("username") String username,
			@PathParam("password") String password,
			@PathParam("filePath") String filePath,
			@PathParam("fileName") String fileName) {

		repositoryURL = repositoryURL.replaceAll("-", "/");

		String fileContent = GetFileContent.getContent(repositoryURL, username,
				password, filePath + "/" + fileName);

		return ConvertClassContentToDocumentation.loadClassDocumentation(
				fileContent, fileName);

	}
}
